package com.wuxl.prada;

/**
 * Description:
 *
 * @author 诸葛小猿
 * @date 2024-12-19
 */
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        String srtFilePath = "F:\\BaiduNetdiskDownload\\穿普拉达的女王\\The.Devil.Wears.Prada.2006.穿普拉达的女王.双语字幕.国英音轨.HR-HDTV.AC3.1024X576.X264.srt";
        String inputVideoPath = "F:\\BaiduNetdiskDownload\\穿普拉达的女王\\The.Devil.Wears.Prada.2006.穿普拉达的女王.双语字幕.国英音轨.HR-HDTV.AC3.1024X576.X264.mkv";
        String outputDir = "F:\\BaiduNetdiskDownload\\穿普拉达的女王\\segment";
        String ffmpeg = "H:\\ffmpeg-7.0.2-full_build\\bin\\ffmpeg.exe";

        try {
            // Parse the SRT file
            List<SrtParser.Subtitle> subtitles = SrtParser.parse(srtFilePath);

            // Extract words and their timestamps
            List<WordExtractor.WordTimestamp> wordTimestamps = WordExtractor.extractWords(subtitles);

            Map<String,List<WordExtractor.WordTimestamp>> map = new HashMap<>();

            for(WordExtractor.WordTimestamp ele : wordTimestamps){
                map.computeIfAbsent(ele.getWord(), k->new ArrayList<WordExtractor.WordTimestamp>());
                map.get(ele.getWord()).add(ele);
            }

            // Clip the video and add subtitles
            VideoClipper.clipVideo(ffmpeg, inputVideoPath, outputDir, map.get("resources"));
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
